package com.sigmatrix.h5.web.controller.utils;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.sigmatrix.h5.entity.v2.CodeFleeCheckRecord;
import com.sigmatrix.h5.entity.v2.DisDealer;
import com.sigmatrix.h5.exception.MessageException;
import com.sigmatrix.h5.service.db.CodeFleeCheckRecordDBService;
import com.sigmatrix.h5.service.db.DisDealerDBService;
import com.sigmatrix.h5.web.BaseController;

/**
 * 通过Dealer 测试mybatic常用操作
 * 
 * @author wei.wang
 *
 */
@RestController
@RequestMapping("/util/test/dealer")
public class TestDealerController extends BaseController {

	@Autowired
	private DisDealerDBService disDealerDBService;
	
	//ok
	@GetMapping("/select/id/{id}/esecode/{esecode}")
	public DisDealer selectById(HttpServletRequest request,@PathVariable Integer id,@PathVariable String esecode) {
		System.out.println(request.getRequestURI());
		System.out.println("====================");
		return disDealerDBService.selectById(id, "_"+esecode);
	}
	
	//ok
	@PostMapping("/insert/esecode/{esecode}")
	public boolean insert(@PathVariable String esecode,@RequestBody DisDealer dealer) {
		dealer.setTablePrefix("_"+esecode);
		return disDealerDBService.insert(dealer);
	}
	
	//ok
	@PostMapping("/selectPage/esecode/{esecode}/size/{size}/current/{current}")
	public Page<DisDealer> selectPage(@PathVariable String esecode,@PathVariable int size,@PathVariable int current,@RequestBody DisDealer shop) {
		shop.setTablePrefix("_"+esecode);
		return disDealerDBService.selectPage(new Page<DisDealer>(current, size), new EntityWrapper<>(shop));
	}
	
	//ok
	@PostMapping("/find/parents/code/{code}/esecode/{esecode}")
	public List<DisDealer> findParentsByCode(@PathVariable String esecode,@PathVariable String code) {
		return disDealerDBService.findParentsByCode(code, esecode);
	}
	
	//ok
	@PostMapping("/find/parents/id/{id}/esecode/{esecode}")
	public List<DisDealer> findParentsById(@PathVariable String esecode,@PathVariable Integer id) {
		return disDealerDBService.findParentsById(id, esecode);
	}
	

}
